package com.r.pan.config;

import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
@RequiredArgsConstructor
public class MvcConfig implements WebMvcConfigurer {

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**") // 所有的当前站点的请求地址，都支持跨域访问。
                .allowedOrigins("http://localhost:8081", "http://127.0.0.1:8081")
                .allowCredentials(true) // 是否支持跨域用户凭证
                .allowedMethods(new String[]{"GET", "POST", "PUT", "DELETE", "OPTIONS"}); // 当前站点支持的跨域请求类型是什么
    }
}
